<template>
    <div>
        <h1>登录页面</h1>
    </div>
    <table class="table table-bordered">
        <tbody>
            <tr>
                <td>账号</td>
                <td><input type="text" v-model="info.name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="info.pass"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="登录" class="btn btn-success" @click="d"></td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
let info: any = reactive({
    name: '',
    pass: ''
})

const d = () => {
    axios({
        url: 'https://localhost:7173/api/User/Login',
        method: 'get',
        params: info
    })

        .then(res => {
            console.log(res);
            if (res.data == res.data) {
                alert("登录成功");
                router.push("/showUser");
                return;
            }
            else if (res.data == -1) {
                alert("账号不存在");
                return;
            }
            else if (res.data == -2) {
                alert("密码错误");
                return;
            }
            else {
                alert("登录失败");
                return;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
</script>

<style scoped></style>